import 'package:flutter/material.dart';
import '../../widgets/IconWidget.dart';
import '../../widgets/inputWidget.dart';
import '../../model/shipuse.dart';
import '../../helper/uidata.dart';
import 'shipuse_authorty.dart';

class ShipUseGuanLiAddPage extends StatefulWidget {
  @override
  ShipUseGuanLiAddPage(this.s1, this.added);
  final ShipUse s1;
  final VoidCallback added;
  @override
  ShipUseGuanLiAddPageState createState() => new ShipUseGuanLiAddPageState();
}

class ShipUseGuanLiAddPageState extends State<ShipUseGuanLiAddPage> {
  late ShipUse X1;

  final TextEditingController c1 = new TextEditingController();
  final TextEditingController c2 = new TextEditingController();
  final TextEditingController c3 = new TextEditingController();
  final TextEditingController c4 = new TextEditingController();

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    X1 = widget.s1;

    c1.text = X1.ManaName;
    c2.text = X1.CZName;
    c3.text = X1.ChuanBo;
    c4.text = X1.ManaPhone;

    if (c1.text.length < 2) c1.text = UIData.CurrentUser!.Name;

    if (c4.text.length < 2) c4.text = UIData.CurrentUser!.Phone;
  }

  upload(BuildContext context) async {
    if (X1.State != 1) {
      return;
    }

    X1.ManaName = c1.text;
    X1.CZName = c2.text;
    X1.ChuanBo = c3.text;
    X1.ManaPhone = c4.text;

    X1.CZPhone = "  ";
    X1.Remark = " ";
    X1.State = 2;
    X1.CunDang = UIData.CurrentUser!.Name;
    await ShipUse.Update(X1);
    widget.added();
    Navigator.of(context).pop();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      //backgroundColor: Colors.white,
      appBar: new AppBar(
        // title: bottomTabs[currentIndex].title,
        title: Text("船艇管理人员确认"),

        // leading: Icon(Icons.menu),
      ),
      body: ShipUseGuanLiAddBody(context),
    );
  }

  List<Widget> getWidgetList(BuildContext context) {
    List<Widget> list1 = <Widget>[];
    List<Widget> list2 = <Widget>[];
    List<Widget> list3 = <Widget>[];

    list1.add(InputWidget.inCard(ShipUseAuthority.GetShipTitle(X1)));

    list2.add(InputWidget.getInput2("拟安排船艇", c3));
    list2.add(Divider(
      height: 0.0,
    ));
    list2.add(InputWidget.getInput("船艇管理人员", c1));
    list2.add(Divider(
      height: 0.0,
    ));
    list2.add(InputWidget.getInput("管理人员电话", c4));
    list2.add(Divider(
      height: 0.0,
    ));
    list2.add(InputWidget.getInput("拟安排船长、船员", c2));

    list1.add(InputWidget.inCard2(list2));
    list1.add(
        InputWidget.inCard(InputWidget.getButton("保存", () => upload(context))));
    //list1.add(getCLWidget(s1.State==6, Helper.DateTimeFormat(s1.HZQMTM), s1.HZQM));
    return list1;
  }

  ShipUseGuanLiAddBody(BuildContext context) => SingleChildScrollView(
        child: ShipUseGuanLiAddFields(context),
      );

  ShipUseGuanLiAddFields(BuildContext context) {
    return Container(child: Column(children: getWidgetList(context)));
  }
}
